const mongoose = require('mongoose')

const user = new mongoose.Schema({
    username: {
        type: String,
        required: true
    },
    phone: {
        type: String,
        required: true
    },
    avatar: {
        type: String,
        default: ''
    },
    sex: {
        type: Number,
        default: 2 // 0 女性, 1, 男性 2， 未知
    },
    address: {
        type: String,
        default: ''
    },
    birthday: {
        type: Date,
        default: null
    },
    password: {
        type: String,
        required: true
    },
    serialNum: { // 员工编号
        type: Number,
        required: true,
        unique: true
    },
    competence: [ // 权限
        {
            type: mongoose.SchemaTypes.ObjectId,
            ref: 'competence'
        }
    ],
    position: {
        type: String,
        required: true
    },
    workStatus: {
        type: Number,
        default: 1   // 1. 在职   2. 离职
    }
}, {versionKey: false, timestamps: {createdAt: 'create_time', updatedAt: 'update_time'}})

module.exports = mongoose.model('user', user)
